home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / message / subcls / syscmd.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-06-13  |  2.0 KB  |  54 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "System Command Demo"
  4.    ClientHeight    =   3255
  5.    ClientLeft      =   1410
  6.    ClientTop       =   2220
  7.    ClientWidth     =   6060
  8.    Height          =   3660
  9.    Left            =   1350
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3255
  12.    ScaleWidth      =   6060
  13.    Top             =   1875
  14.    Width           =   6180
  15.    Begin MsgHook MsgHook 
  16.       Left            =   120
  17.       Top             =   120
  18.    End
  19. Option Explicit
  20. ' Windows declarations
  21. Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
  22. Declare Function AppendMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As Any) As Integer
  23. Declare Function InvokeWindowProc Lib "msghook.vbx" (ByVal hWnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Long
  24. ' Windows constants
  25. Const WM_SYSCOMMAND = &H112
  26. Const MF_STRING = &H0
  27. Const MF_SEPARATOR = &H800
  28. ' ID for new About command (must be < &HF000)
  29. Const IDM_ABOUT = 1
  30. Sub Form_Load ()
  31.     Dim i As Integer
  32.     Dim hMenu As Integer
  33.     ' Add "About..." command to system menu
  34.     hMenu = GetSystemMenu(Me.hWnd, False)
  35.     i = AppendMenu(hMenu, MF_SEPARATOR, 0, 0&)
  36.     i = AppendMenu(hMenu, MF_STRING, IDM_ABOUT, "&About...")
  37.     ' Setup MsgHook
  38.     MsgHook.HwndHook = Me.hWnd
  39.     MsgHook.Message(WM_SYSCOMMAND) = True
  40. End Sub
  41. Sub MsgHook_Message (msg As Integer, wParam As Integer, lParam As Long, result As Long)
  42.     ' Look for WM_SYSCOMMAND message with About command
  43.     If msg = WM_SYSCOMMAND Then
  44.         Select Case wParam
  45.             Case IDM_ABOUT
  46.                 frmAbout.Show 1
  47.                 result = 0
  48.                 Exit Sub
  49.         End Select
  50.     End If
  51.     ' Pass along to default handler if message not processed
  52.     result = InvokeWindowProc(MsgHook.HwndHook, msg, wParam, lParam)
  53. End Sub
  54.